package com.shajj.data;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;
import com.shajj.data.rss.RssSearchJanitor;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class RssRecord implements Serializable {

	private static final long serialVersionUID = 1L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

	@Persistent
	private Text content;

	@Persistent
    private Set<String> fts;

	@Persistent
	private Date time;

	public RssRecord(Long id, String content) {
		this(id, content, new Date());
	}

	public RssRecord(Long id, String content, Date time) {
		this.id = id;
		this.fts = new HashSet<String>();
		this.time = time;
		this.content = new Text(content);

		RssSearchJanitor.updateFTSStuffForThread(this);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getContent() {
		return ShajjUtil.replace(content.getValue());
	}

	public String getValue() {
		return ShajjUtil.replace(content.getValue());
	}

	public void setContent(String content) {
		this.content = new Text(content);
	}

	public String getTimeString() {
		return ShajjUtil.DateFormat(time);
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public void setFts(Set<String> fts) {
		this.fts = fts;
	}

	public Set<String> getFts() {
		return fts;
	}

	@Override
	public String toString() {
		return "Thread [content=" + content + ", fts=" + fts + ", id=" + id + ", time=" + time + "]";
	}
}
